import { asyncRoutes, constantRoutes } from '@/router'
import store from '@/store'

const state = {
  routes: []
}

const mutations = {
  setRoutes(state, data) {
    // console.log(10, data)
    // console.log(11, state.routes)
    state.routes = [...constantRoutes, ...data]
  }
}

const actions = {
  filterRoutes() {
    const menus = store.state.user.profile.roles.menus
    // console.log(19, menus)
    // console.log(20, asyncRoutes)
    const routes = asyncRoutes.filter(item => {
      return menus.includes(item.name)
    })
    // console.log(24, routes)
    store.commit('permission/setRoutes', routes)
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
